package com.example.actuator.endpoint;

import com.example.actuator.vo.SwitchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

//(GET) http://localhost:8080/actuator/customBean
//(POST) http://localhost:8080/actuator/customBean?onOrOff1=OFF&onOrOff2=OFF
@Component
@Endpoint(id="customBean")
public class CustomBeanEndpoint {

    @Autowired
    private SwitchVO switchVO;

    @ReadOperation
    public SwitchVO customEndPointRead() {
        return switchVO;
    }

    @WriteOperation
    public String customEndPointWrite(String onOrOff1, String onOrOff2) {
        switchVO.setOnOrOff1(onOrOff1);
        switchVO.setOnOrOff2(onOrOff2);
        return "success: " + switchVO;
    }
}
